/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 21-sep-2011, 14:11:14
 */
package GUI;

import Logica.*;
import Data.*;
import MyLinkedList.LinkedList;
import javax.swing.JOptionPane;


/**
 *
 * @author Silvana
 */
public class Principal extends javax.swing.JFrame {
   Management m= new Management();
    /** Creates new form Principal */
    public Principal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupPais = new javax.swing.ButtonGroup();
        buttonGroupUnidad = new javax.swing.ButtonGroup();
        jPanelPrincipal = new javax.swing.JPanel();
        jPanelOrden = new javax.swing.JPanel();
        jPanelPais = new javax.swing.JPanel();
        jrbEliminarPais = new javax.swing.JRadioButton();
        jrbInsertarPais = new javax.swing.JRadioButton();
        jrbMostrarPais = new javax.swing.JRadioButton();
        btnAceptarPaises = new javax.swing.JButton();
        jPanelUnidad = new javax.swing.JPanel();
        btnAceptarUnidad = new javax.swing.JButton();
        jrbInsertarUnidad = new javax.swing.JRadioButton();
        jrbMostarUnidad = new javax.swing.JRadioButton();
        jPanelPaisOcupado = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        btnGenerar = new javax.swing.JButton();
        jPanelsalir = new javax.swing.JPanel();
        btnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanelPrincipal.setLayout(new java.awt.BorderLayout());

        jPanelOrden.setLayout(new javax.swing.BoxLayout(jPanelOrden, javax.swing.BoxLayout.LINE_AXIS));

        jPanelPais.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true), "País", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 12))); // NOI18N
        jPanelPais.setPreferredSize(new java.awt.Dimension(260, 187));

        buttonGroupPais.add(jrbEliminarPais);
        jrbEliminarPais.setText("Borrar");

        buttonGroupPais.add(jrbInsertarPais);
        jrbInsertarPais.setText("Insertar");
        jrbInsertarPais.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbInsertarPaisActionPerformed(evt);
            }
        });

        buttonGroupPais.add(jrbMostrarPais);
        jrbMostrarPais.setText("Mostrar");

        btnAceptarPaises.setText("Aceptar");
        btnAceptarPaises.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarPaisesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelPaisLayout = new javax.swing.GroupLayout(jPanelPais);
        jPanelPais.setLayout(jPanelPaisLayout);
        jPanelPaisLayout.setHorizontalGroup(
            jPanelPaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelPaisLayout.createSequentialGroup()
                .addContainerGap(168, Short.MAX_VALUE)
                .addComponent(btnAceptarPaises)
                .addContainerGap())
            .addGroup(jPanelPaisLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jrbInsertarPais)
                .addContainerGap(178, Short.MAX_VALUE))
            .addGroup(jPanelPaisLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jrbEliminarPais)
                .addContainerGap(188, Short.MAX_VALUE))
            .addGroup(jPanelPaisLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jrbMostrarPais)
                .addContainerGap(180, Short.MAX_VALUE))
        );
        jPanelPaisLayout.setVerticalGroup(
            jPanelPaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPaisLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jrbInsertarPais)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jrbEliminarPais)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jrbMostrarPais)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addComponent(btnAceptarPaises)
                .addContainerGap())
        );

        jPanelOrden.add(jPanelPais);

        jPanelUnidad.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true), "Unidad Militar"));
        jPanelUnidad.setPreferredSize(new java.awt.Dimension(260, 187));

        btnAceptarUnidad.setText("Aceptar");
        btnAceptarUnidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarUnidadActionPerformed(evt);
            }
        });

        buttonGroupUnidad.add(jrbInsertarUnidad);
        jrbInsertarUnidad.setText("Insertar");

        buttonGroupUnidad.add(jrbMostarUnidad);
        jrbMostarUnidad.setText("Mostrar");

        javax.swing.GroupLayout jPanelUnidadLayout = new javax.swing.GroupLayout(jPanelUnidad);
        jPanelUnidad.setLayout(jPanelUnidadLayout);
        jPanelUnidadLayout.setHorizontalGroup(
            jPanelUnidadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelUnidadLayout.createSequentialGroup()
                .addContainerGap(168, Short.MAX_VALUE)
                .addComponent(btnAceptarUnidad)
                .addContainerGap())
            .addGroup(jPanelUnidadLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jrbInsertarUnidad)
                .addContainerGap(178, Short.MAX_VALUE))
            .addGroup(jPanelUnidadLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jrbMostarUnidad)
                .addContainerGap(180, Short.MAX_VALUE))
        );
        jPanelUnidadLayout.setVerticalGroup(
            jPanelUnidadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelUnidadLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jrbInsertarUnidad)
                .addGap(18, 18, 18)
                .addComponent(jrbMostarUnidad)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(btnAceptarUnidad)
                .addContainerGap())
        );

        jPanelOrden.add(jPanelUnidad);

        jPanelPrincipal.add(jPanelOrden, java.awt.BorderLayout.PAGE_START);

        jPanelPaisOcupado.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true), "Pais Ocupado "));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "País", "Unidad Militar", "Poder de Fuego "
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        btnGenerar.setText("Generar Lista");
        btnGenerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelPaisOcupadoLayout = new javax.swing.GroupLayout(jPanelPaisOcupado);
        jPanelPaisOcupado.setLayout(jPanelPaisOcupadoLayout);
        jPanelPaisOcupadoLayout.setHorizontalGroup(
            jPanelPaisOcupadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPaisOcupadoLayout.createSequentialGroup()
                .addGap(175, 175, 175)
                .addComponent(btnGenerar, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(193, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelPaisOcupadoLayout.createSequentialGroup()
                .addContainerGap(36, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35))
        );
        jPanelPaisOcupadoLayout.setVerticalGroup(
            jPanelPaisOcupadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPaisOcupadoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnGenerar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanelPrincipal.add(jPanelPaisOcupado, java.awt.BorderLayout.CENTER);

        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelsalirLayout = new javax.swing.GroupLayout(jPanelsalir);
        jPanelsalir.setLayout(jPanelsalirLayout);
        jPanelsalirLayout.setHorizontalGroup(
            jPanelsalirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelsalirLayout.createSequentialGroup()
                .addContainerGap(387, Short.MAX_VALUE)
                .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32))
        );
        jPanelsalirLayout.setVerticalGroup(
            jPanelsalirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelsalirLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(btnSalir)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jPanelPrincipal.add(jPanelsalir, java.awt.BorderLayout.PAGE_END);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 523, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jrbInsertarPaisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbInsertarPaisActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jrbInsertarPaisActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
     this.dispose();        // TODO add your handling code here:
    }//GEN-LAST:event_btnSalirActionPerformed

    private void btnGenerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnGenerarActionPerformed

    private void btnAceptarUnidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarUnidadActionPerformed
    
        if (this.jrbInsertarUnidad.isSelected())    
        {
            InsertarUnidad.insertarUnidades();
            LinkedList unidades=InsertarUnidad.devolver();
            m.agregarUnidadesMilitares(unidades);
        }
        if(this.jrbMostarUnidad.isSelected()){
            
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_btnAceptarUnidadActionPerformed

    private void btnAceptarPaisesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarPaisesActionPerformed
        /* preguntar cual radio esta seleccionado y abre la ventana que corresponde
         */
        
        if (this.jrbInsertarPais.isSelected())
        {
          InsertarPais.insertarPaises();
          m.agregarPaises(InsertarPais.devolver());
         
                         
           
        }
        if (this.jrbEliminarPais.isSelected())
        {
            EliminarPais eliminar = new EliminarPais (this, true);
            eliminar.setVisible(true);
        }
        
        if (this.jrbMostrarPais.isSelected())
        {
            MostrarPaises mostrar = new MostrarPaises (this,true);
            mostrar.setVisible(true);
        }
        
    }//GEN-LAST:event_btnAceptarPaisesActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptarPaises;
    private javax.swing.JButton btnAceptarUnidad;
    private javax.swing.JButton btnGenerar;
    private javax.swing.JButton btnSalir;
    private javax.swing.ButtonGroup buttonGroupPais;
    private javax.swing.ButtonGroup buttonGroupUnidad;
    private javax.swing.JPanel jPanelOrden;
    private javax.swing.JPanel jPanelPais;
    private javax.swing.JPanel jPanelPaisOcupado;
    private javax.swing.JPanel jPanelPrincipal;
    private javax.swing.JPanel jPanelUnidad;
    private javax.swing.JPanel jPanelsalir;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JRadioButton jrbEliminarPais;
    private javax.swing.JRadioButton jrbInsertarPais;
    private javax.swing.JRadioButton jrbInsertarUnidad;
    private javax.swing.JRadioButton jrbMostarUnidad;
    private javax.swing.JRadioButton jrbMostrarPais;
    // End of variables declaration//GEN-END:variables

    
}
